﻿using ControllerStudy2.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Mvc;

namespace ControllerStudy2.Controllers
{
    public class MailController : Controller
    {
        //
        // GET: /Mail/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Send(MailInfo model)
        {
            // Tạo thư
            var mail = new MailMessage();
            mail.From = new MailAddress("Nhất Nghệ <" + model.Sender + ">");
            mail.To.Add(model.Receiver);
            mail.Subject = model.Subject;
            mail.Body = model.Content;

            mail.ReplyToList.Add(model.Sender);
            mail.IsBodyHtml = true;

            // Kết nối SmtpServer
            var smtp = new SmtpClient("smtp.gmail.com", 25);
            smtp.EnableSsl = true;
            smtp.Credentials = new NetworkCredential("kentphp2@gmail.com", "songlong");

            // Gửi thư
            smtp.Send(mail);

            return View("Index");
        }
	}
}